<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="用户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务名" prop="typeName">
        <el-input
          v-model="queryParams.typeName"
          placeholder="请输入服务名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="身份证正面照" prop="frontIdImg">-->
        <!--<el-input-->
          <!--v-model="queryParams.frontIdImg"-->
          <!--placeholder="请输入身份证正面照"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="身份证背面照" prop="backIdImg">-->
        <!--<el-input-->
          <!--v-model="queryParams.backIdImg"-->
          <!--placeholder="请输入身份证背面照"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="上岗资格证" prop="certificateImg">-->
        <!--<el-input-->
          <!--v-model="queryParams.certificateImg"-->
          <!--placeholder="请输入上岗资格证"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="证件照" prop="img4">-->
        <!--<el-input-->
          <!--v-model="queryParams.img4"-->
          <!--placeholder="请输入证件照"-->
          <!--clearable-->
          <!--size="small"-->
          <!--@keyup.enter.native="handleQuery"-->
        <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="工人审核状态" prop="status">-->
        <!--<el-select v-model="queryParams.status" placeholder="请选择工人审核状态" clearable size="small">-->
          <!--<el-option label="请选择字典生成" value="" />-->
        <!--</el-select>-->
      <!--</el-form-item>-->
      <el-form-item label="审核状态" prop="withdrawalStatus">
      <el-select v-model="queryParams.status" placeholder="请选择工人审核状态" clearable size="small">
        <!--          <el-option v-for="item in [{value: '0', label: '待审核' }, {value: '1', label: '审核成功' },{value: '2', label: '审核失败' }]"-->
        <!--                     :key="item.value" :label="item.label" :value="item.value" />-->
        <el-option v-for="item in sysOptions"
                   :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue" />
      </el-select>
    </el-form-item>
      <el-form-item label="失败原因" prop="reason">
        <el-input
          v-model="queryParams.reason"
          placeholder="请输入审核失败原因"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!--<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="primary"-->
          <!--icon="el-icon-plus"-->
          <!--size="mini"-->
          <!--@click="handleAdd"-->
          <!--v-hasPermi="['system:apply:add']"-->
        <!--&gt;新增</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--icon="el-icon-edit"-->
    <!--type="success"-->
          <!--size="mini"-->
          <!--:disabled="single"-->
          <!--@click="handleUpdate"-->
          <!--v-hasPermi="['system:apply:edit']"-->
        <!--&gt;修改</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="danger"-->
          <!--icon="el-icon-delete"-->
          <!--size="mini"-->
          <!--:disabled="multiple"-->
          <!--@click="handleDelete"-->
          <!--v-hasPermi="['system:apply:remove']"-->
        <!--&gt;删除</el-button>-->
      <!--</el-col>-->
      <!--<el-col :span="1.5">-->
        <!--<el-button-->
          <!--type="warning"-->
          <!--icon="el-icon-download"-->
          <!--size="mini"-->
          <!--@click="handleExport"-->
          <!--v-hasPermi="['system:apply:export']"-->
        <!--&gt;导出</el-button>-->
      <!--</el-col>-->
    <!--</el-row>-->

    <el-table v-loading="loading" :data="applyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="服务名" align="center" prop="typeName" />
      <el-table-column label="身份证正面照" align="center" prop="frontIdImg">
        <template slot-scope="scope">
          <img :src="scope.row.frontIdImg" alt="11" width="50px" height="50px" >
        </template>
      </el-table-column>
      <el-table-column label="身份证背面照" align="center" prop="backIdImg" >
        <template slot-scope="scope">
          <img :src="scope.row.backIdImg" alt="11" width="50px" height="50px" >
        </template>
      </el-table-column>
      <el-table-column label="上岗资格证" align="center" prop="certificateImg" >
        <template slot-scope="scope">
          <img :src="scope.row.certificateImg" alt="11" width="50px" height="50px" >
        </template>
      </el-table-column>
      <el-table-column label="证件照" align="center" prop="img4" >
        <template slot-scope="scope">
          <img :src="scope.row.img4" alt="11" width="50px" height="50px" >
        </template>
      </el-table-column>
      <el-table-column label="提现审核状态 " align="center" prop="status" :formatter="sysFormat" />
      <el-table-column label="审核失败原因" align="center" prop="reason" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
          v-if="scope.row.status === 0 "
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:apply:edit']"
          >审核</el-button>
          <!--<el-button-->
            <!--size="mini"-->
            <!--type="text"-->
            <!--icon="el-icon-delete"-->
            <!--@click="handleDelete(scope.row)"-->
            <!--v-hasPermi="['system:apply:remove']"-->
          <!--&gt;删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改入驻申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" :inline="true">
        <el-form-item label="用户名" prop="userName">
          <el-input v-model="form.userName" disabled placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="服务名" prop="typeName">
          <el-input v-model="form.typeName" disabled placeholder="请输入服务id" />
        </el-form-item>
        <el-form-item label="身份证正面照" prop="frontIdImg">
          <img :src="tu.frontIdImg" alt="11"  >
          <!--<el-input v-model="form.frontIdImg" placeholder="请输入身份证正面照" />-->
        </el-form-item>
        <el-form-item label="身份证背面照" prop="backIdImg">
          <img :src="tu.backIdImg" alt="11"  >
          <!--<el-input v-model="form.backIdImg" placeholder="请输入身份证背面照" />-->
        </el-form-item>
        <el-form-item label="上岗资格证" prop="certificateImg">
          <img :src="tu.certificateImg" alt="11" >
          <!--<el-input v-model="form.certificateImg" placeholder="请输入上岗资格证" />-->
        </el-form-item>
        <el-form-item label="证件照" prop="img4">
          <img :src="tu.img4" alt="11">
          <!--<el-input v-model="form.img4" placeholder="请输入证件照" />-->
        </el-form-item>
        <el-form-item label="审核失败原因" prop="reason">
          <el-input v-model="form.reason" type="textarea" placeholder="请输入审核失败原因"  style="width:400px;"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-bottom: 30px">
        <el-button type="primary"  style="float: left;" @click="submitForm">审核成功</el-button>
        <el-button style="float: right;"  @click="submitForm1">审核失败</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listApply, getApply, delApply, addApply, updateApply, exportApply } from "@/api/system/apply";

export default {
  name: "Apply",
  data() {
    return {
      // 遮罩层
      loading: true,
      tu:[],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      sysOptions:[],
      // 入驻申请表格数据
      applyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mobileUserId: undefined,
        typeId: undefined,
        frontIdImg: undefined,
        backIdImg: undefined,
        certificateImg: undefined,
        img4: undefined,
        status: undefined,
        reason: undefined,
      },
      // 表单参数
      form: {
        sysOptions:[]
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_audit_status").then(response => {
      console.log(response)
      this.sysOptions = response.data;
    });
  },
  methods: {

    /** 查询入驻申请列表 */
    sysFormat(row, column) {
      return this.selectDictLabel(this.sysOptions, row.status);
    },
    getList() {
      this.loading = true;
      listApply(this.queryParams).then(response => {
        response.rows.forEach((items,i)=>{
          items.frontIdImg  =  process.env.VUE_APP_BASE_API + items.frontIdImg
          items.backIdImg  =  process.env.VUE_APP_BASE_API + items.backIdImg
          items.certificateImg  =  process.env.VUE_APP_BASE_API + items.certificateImg
          items.img4 =  process.env.VUE_APP_BASE_API + items.img4
          console.log(items.frontIdImg);
        })
        this.applyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        typeName:undefined,
        userName:undefined,
        applyId: undefined,
        mobileUserId: undefined,
        typeId: undefined,
        frontIdImg: undefined,
        backIdImg: undefined,
        certificateImg: undefined,
        img4: undefined,
        status: "0",
        reason: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.applyId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加入驻申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const applyId = row.applyId || this.ids
      getApply(applyId).then(response => {
        console.log(response.rows[0]);
        this.form = response.rows[0];
        this.tu.frontIdImg  =  process.env.VUE_APP_BASE_API +  this.form.frontIdImg
        this.tu.backIdImg  =  process.env.VUE_APP_BASE_API +   this.form.backIdImg
        this.tu.certificateImg  =  process.env.VUE_APP_BASE_API +  this.form.certificateImg
        this.tu.img4 =  process.env.VUE_APP_BASE_API +  this.form.img4
        this.open = true;
        this.title = "审核入驻申请";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.status =1;
          if (this.form.applyId != undefined) {
            updateApply(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addApply(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    submitForm1: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.status = 2 ;
          if (this.form.applyId != undefined) {
            updateApply(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addApply(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const applyIds = row.applyId || this.ids;
      this.$confirm('是否确认删除入驻申请编号为"' + applyIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delApply(applyIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有入驻申请数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportApply(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
